from socket import socket, AF_INET, SOCK_DGRAM

def start_server():
    re_socket = socket(AF_INET, SOCK_DGRAM) #定义一个UDP socket
    host = '127.0.0.1'
    port = 9999
    re_socket.bind((host, port)) #绑定主机和端口,无须监听listen和等待连接accept

    while True:
        recv_data, addr = re_socket.recvfrom(1024)  # 接受数据并解包数据和地址
        print("客户说：", recv_data.decode('utf-8'))
        if recv_data.decode('utf-8') == 'bye':   #客户发送bye则结束
            break
        send_data = input("客服说：")
        re_socket.sendto(send_data.encode('utf-8'), addr) #发送数据

    re_socket.close()

if __name__ == '__main__':
    start_server()